frappe.ui.form.on(cur_frm.doctype, {
	refresh: function(frm){
        const doctypes = ['Stock Entry', 'Delivery Note', 'Purchase Receipt', 'Stock Reconciliation']
        if (in_list(doctypes,frm.doctype) && frm.doc.docstatus == 1 ){
            frappe.db.get_value('Warehouse Task', 
                {'voucher_type': frm.doctype,
                 'voucher_no': frm.docname
                }, 'name', (r) => {
                if (r && r.name) {
                    frm.add_custom_button(__("Warehouse Task"), function() {
                        frappe.set_route("form", "Warehouse Task", r.name);
                    }, __("View"));     
                }
            });            
        }
    }
})